// Copyright (C) 2006-2007 - Ivan Zhakov (chemodax@gmail.com)
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

using System;
using System.IO;

namespace CTCDecoder
{
    public class App
    {
        [STAThread]
        static void Main(string[] args)
        {
            if (args.Length <= 0)
            {
                Console.Error.WriteLine("Usage: CTCDecoder <CTMenu-resource> [CTMenu-resoirce]");
                return ;
            }

            CTCAnalyzer analyzer = new CTCAnalyzer();

            foreach(string arg in args)
            {
                Console.Error.WriteLine("Reading file {0}...", arg);

                FileStream file = new FileStream(arg, FileMode.Open);
                CTCDecoder ctc = new CTCDecoder(file);
                file.Close();

                foreach(CTCDecoder.MenuItem menu in ctc.MenuTable)
                {
                    analyzer.AddNode(menu.Menu, menu.RelativeGroup, menu.CommandName);
                }
        
                foreach(CTCDecoder.GroupItem group in ctc.GroupTable)
                {
                    analyzer.AddNode(group.Group, group.RelativeGroup, String.Empty);
                }
            
                foreach(CTCDecoder.CommandItem cmd in ctc.CommandTable)
                {
                    analyzer.AddNode(cmd.Command, cmd.RelativeGroup, cmd.CommandName);
                }

                foreach(CTCDecoder.PlacementItem item in ctc.PlacementTable)
                {
                    analyzer.AddNode(item.Command, item.RelativeGroup, String.Empty);
                }
            }                        

            analyzer.Print(Console.Out);
        }
    }
}
